﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProStore
{
    public partial class Servidores : Form
    {
        Registro_control regcontrol = new Registro_control();

        public Servidores()
        {
            InitializeComponent();
        }

        private void Servidores_Load(object sender, EventArgs e)
        {
            string[] data = regcontrol.ReadServerInfo();
            if (data != null)
            {
                txtServidor.Text = data[0];
                txtUsuario.Text = data[1];
                txtPassword.Text = data[2];
            }else
            {
                Close();
            }
        }


        private void button1_Click(object sender, EventArgs e)
        {
            if(txtServidor.Text == "" || txtUsuario.Text == "" || txtPassword.Text == "")
            {
                MessageBox.Show("Debe ingresar todos los datos.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                
            }else
            {
                if(regcontrol.SaveServerInfo(txtServidor.Text, txtUsuario.Text, txtPassword.Text))
                {
                    Panel.ServerIP = txtServidor.Text;
                    Panel.User = txtUsuario.Text;
                    Panel.Password = txtPassword.Text;

                    MessageBox.Show("Datos guardados con éxito.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Close();
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }
    }
}
